package com.hooker.plugins;

import android.content.Context;

import com.hooker.base.BaseXposedLoader;
import com.hooker.settings.HLog;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class PluginString extends BaseXposedLoader {

    public PluginString(Context context, XC_LoadPackage.LoadPackageParam loadParams) {
        super(context, loadParams);
    }

    @Override
    public void hook(Object... calls) {

    }

    @Override
    public void hook(Context context, XC_LoadPackage.LoadPackageParam loadParams) {
        hookString(loadParams);
    }

    private void hookString(XC_LoadPackage.LoadPackageParam lp) {
        hookAllConstructor(String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
                int args = param.args.length;
                StringBuilder sb = new StringBuilder("hookString :");
                for (int i = 0; i < args; i++) {
                    sb.append("arg" + i).append("=" + param.args[i] + "; ");
                }
                HLog.o(sb.toString());
            }
        });


        hookMethod(String.class, "startsWith", String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
                HLog.o("hookString.startsWith: " + param.thisObject.toString() + ",   " + param.args[0].toString());
                new Exception().printStackTrace();
            }
        });


        hookMethod(String.class, "endsWith", String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
                HLog.o("hookString.endsWith: " + param.thisObject.toString() + ",   " + param.args[0].toString());
                new Exception().printStackTrace();
            }
        });

        hookMethod(String.class, "equals", Object.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
                HLog.o("hookString.equals: " + param.thisObject.toString() + ",   " + param.args[0].toString());
                new Exception().printStackTrace();
            }
        });
    }
}
